using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace Domain.Core.Tests
{
    /// <summary>
    /// The author of the <see cref="Money"/> class provided some tests and these smaller more focused build on
    /// them.
    /// </summary>
    [TestFixture]
    public class MoneyTests
    {
        # region Constants

        const decimal firstValue = (decimal)5.4;
        const decimal secondValue = (decimal)6.9;

        # endregion

        # region Tests

        [Test]
        public void CanCastAsDecimal()
        {
            Money money = new Money(MoneyCurrency.PoundSterling, firstValue);

            Assert.AreEqual(firstValue, (decimal)money, "Explicit cast to decimal failed to produce expected result.");
        }

        # endregion

        # region Tests - Add

        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void CannotAddWithDifferentCurrencies()
        {
            Money pulaMoney = new Money(MoneyCurrency.Pula, firstValue);
            Money francMoney = new Money(MoneyCurrency.FrancCongolais, firstValue);

            Money result = pulaMoney + francMoney;
        }

        [Test]
        public void CanAddZeroToZero()
        {
            Money firstZeroMoney = Money.Zero;
            Money secondZeroMoney = Money.Zero;

            Money result = firstZeroMoney + secondZeroMoney;

            Assert.AreEqual(0, (decimal)result);
        }

        [Test]
        public void CanAddZeroToNonZero()
        {
            Money firstZeroMoney = Money.Zero;
            Money nonZeroMoney = CreateMoneyWithUkCurrency(secondValue);

            Money result = firstZeroMoney + nonZeroMoney;

            Assert.AreEqual(secondValue, (decimal)result);
        }

        [Test]
        public void CanAdd()
        {
            decimal expectedResult = firstValue + secondValue;

            Money firstMoney = CreateMoneyWithUkCurrency(firstValue);
            Money secondMoney = CreateMoneyWithUkCurrency(secondValue);
            Money result = firstMoney + secondMoney;

            Assert.AreEqual(expectedResult, (decimal)result, "The money class addition failed to produce the expected result.");
        }

        # endregion

        # region Support Methods

        private Money CreateMoneyWithUkCurrency(decimal value)
        {
            return new Money(MoneyCurrency.PoundSterling, value);
        }

        # endregion
    }
}
